<?php
class OrdersProduct extends AppModel {

    var $name = 'OrdersProduct';
    var $validate = array(
            'orders_id' => array('notempty'),
            'products' => array('notempty'),
            'size' => array('notempty'),
            'quantity' => array('numeric'),
            'price' => array('notempty')
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
            'Order' => array(
                    'className' => 'Order',
                    'foreignKey' => 'orders_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            )
    );

    public function fromCart($cartItem){
        $product = array();

        foreach ($cartItem['sizes'] as $size) {
            $orderProduct = array(
                'product' => $cartItem['name'],
                'size'    => $size['name'],
                'quantity' => $size['quantity'],
                'price'     => $size['price']
            );
            $product[] = $orderProduct;
        }

        return $product;
    }

}
?>